-- @owner: @kyeleze
-- @date: 2022/5/16
-- @testpoint: cascade\restrict参数增减，删除成功

--step1:建立自定义类型转换函数;expect:创建函数成功
create or replace function timezone_to_secondsinteger
(
    in time with time zone
)
returns integer
as
$$
declare
seconds integer;
begin
select (
extract(hour from $1)::integer * 3600
+ extract(minute from $1)::integer * 60
+ extract(seconds from $1)::integer* 1) into seconds;
return seconds;
end;
$$ language plpgsql;
/
--step2:创建显式转换关系;expect:创建转换关系成功
drop cast if exists(time with time zone as integer);
drop cast if exists(text as time with time zone);
drop cast if exists(abstime as reltime);
create cast(time with time zone as integer) with function timezone_to_secondsinteger(time with time zone);
create cast(text as time with time zone) with inout;
create cast(abstime as reltime) without function;

--step3:使用参数restrict删除创建的转关系;expect:删除转换关系成功
drop cast if exists(text as time with time zone) restrict;

--step4:使用参数cascade删除创建的转关系;expect:删除转换关系成功
drop cast if exists(time with time zone as integer) cascade;

--step5:不使用参数restrict/cascade删除创建的转关系;expect:删除转换关系成功
drop cast if exists(abstime as reltime);

--step6:清理环境;expect:清理环境成功
drop function if exists timezone_to_secondsinteger(time with time zone) cascade;
